#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include "mytools.h"
#include <QMessageBox>
#include <QTimer>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("红警共和国之辉修改器");

    QTimer::singleShot(100, this, [=](){
        bool r = MyTools::findGame("Red Alert 2", "Red Alert 2");

        if(!r)
        {
            QMessageBox::warning(this, "警告", "请先启动游戏，再启动修改器!", QMessageBox::Ok);
            exit(0);
        }
    });

    QTimer* t = new QTimer();
    connect(t, &QTimer::timeout, [=](){
        on_pushButton_clicked();
    });
    t->start(10000);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    MyTools::updateValue(ui->lineEdit->text());
}
